package com.jwsoft.manager.core.gateway.controller;

import com.bifang.assistant.common.constants.Validators;
import com.bifang.engine.assistant.core.domain.AppResponse;
import com.bifang.engine.protect.core.annotation.Idempotent;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.bifang.module.base.common.vo.excel.ExcelReadVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.core.utils.ExcelFileUtil;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.eduLotteryAnnouncement.EduLotteryAnnouncementKeyVO;
import com.jwsoft.manager.common.vo.eduLotteryAnnouncementDetail.EduLotteryAnnouncementDetailKeyVO;
import com.jwsoft.manager.common.vo.eduLotteryAnnouncementDetail.EduLotteryAnnouncementDetailQueryVO;
import com.jwsoft.manager.common.vo.eduLotteryAnnouncementDetail.EduLotteryAnnouncementDetailVO;
import com.jwsoft.manager.core.integration.EduLotteryAnnouncementDetailIntegration;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 金华摇号结果公示详情网关
 *
 * @author wangt
 * @since 2024-06-16
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "金华摇号结果公示详情", description = "金华摇号结果公示详情")
public class EduLotteryAnnouncementDetailController {

    @Autowired
    public EduLotteryAnnouncementDetailIntegration eduLotteryAnnouncementDetailIntegration;

    @Operation(summary = "金华摇号结果公示详情分页查询",description = "金华摇号结果公示详情分页查询")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduLotteryAnnouncementDetailVO>> getList(@RequestBody @Validated EduLotteryAnnouncementDetailQueryVO vo) {
        return AppResponse.successData(eduLotteryAnnouncementDetailIntegration.getList(vo));
    }

    @Operation(summary = "金华摇号结果公示详情根据主键查询详情",description = "金华摇号结果公示详情根据主键查询详情")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduLotteryAnnouncementDetailVO> getById(@RequestBody @Validated EduLotteryAnnouncementDetailKeyVO vo) {
        return AppResponse.successData(eduLotteryAnnouncementDetailIntegration.getById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "金华摇号结果公示详情新增",description = "金华摇号结果公示详情新增")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduLotteryAnnouncementDetailVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduLotteryAnnouncementDetailVO vo) {
        return AppResponse.successData(eduLotteryAnnouncementDetailIntegration.add(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "金华摇号结果公示详情修改",description = "金华摇号结果公示详情修改")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduLotteryAnnouncementDetailVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduLotteryAnnouncementDetailVO vo) {
        return AppResponse.successData(eduLotteryAnnouncementDetailIntegration.edit(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "金华摇号结果公示详情删除",description = "金华摇号结果公示详情删除")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduLotteryAnnouncementDetailKeyVO vo) {
        eduLotteryAnnouncementDetailIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Operation(summary = "根据摇号结果公告id查询名单 ",description = "根据摇号结果公告id查询名单 ")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0007", produces = "application/json;charset=UTF-8")
    public AppResponse<List<EduLotteryAnnouncementDetailVO>> getListById(@RequestBody @Validated EduLotteryAnnouncementKeyVO vo) {
        return AppResponse.successData(eduLotteryAnnouncementDetailIntegration.getListById(vo));
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "摇号结果公示导入（PC）",description = "摇号结果公示导入")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0008", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public AppResponse<ExcelReadVO> readByCode(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            HttpServletResponse response) {
        ExcelVO vo = ExcelFileUtil.getExcelVO(request, response, paramMap);
        MultipartFile file = ExcelFileUtil.getExcelFile(request);
        EduLotteryAnnouncementDetailQueryVO queryVO = new EduLotteryAnnouncementDetailQueryVO();
        queryVO.setSchoolId(paramMap.get("schoolId").toString());
        queryVO.setSchoolName(paramMap.get("schoolName").toString());
        queryVO.setLotteryAnnouncementId(Long.valueOf(paramMap.get("lotteryAnnouncementId").toString()));

        return AppResponse.successData(eduLotteryAnnouncementDetailIntegration.readExcel(vo, file, queryVO));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "摇号结果导出", description = "摇号结果导出")
    @PostMapping(value = "/eduLotteryAnnouncementDetail0009", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public void exportInfo(@RequestBody @Validated EduLotteryAnnouncementDetailQueryVO vo, HttpServletResponse response) {
        eduLotteryAnnouncementDetailIntegration.exportInfo(vo, response);
    }

}
